package com.qf.controller;


import com.qf.pojo.Student;
import com.qf.pojo.Teacher;
import com.qf.service.TeacherService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    @GetMapping("/selectAllTeacher")
    public ResultMsg selectAllTeacher(@RequestParam(required = false, defaultValue = "-1") Integer teacherId, @RequestParam(required = false, defaultValue = "-1") Integer teacherStatus, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit) {
        return teacherService.selectAllTeacher(teacherId,teacherStatus,page,limit);
    }
    @GetMapping("/selectOneTeacher")
    public ResultMsg selectOneTeacher(@RequestParam(required = false) Integer teacherId) {
        ResultMsg resultMsg = teacherService.selectOneTeacher(teacherId);
        return resultMsg;
    }

    @PutMapping("/updateTeacher")
    public ResultMsg updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateTeacher(teacher);
    }

    @PutMapping("/insertTeacher")
    public ResultMsg insertTeacher(@RequestBody Teacher teacher) {
        return teacherService.insertTeacher(teacher);
    }

    @PutMapping("/updateTeacherStatus")
    public ResultMsg updateTeacherStatus(@RequestBody Map<String, Object> map) {
        return teacherService.updateTeacherStatus((List<Integer>) map.get("studentIds"), (Integer) map.get("teacherStatus"));
    }

    @DeleteMapping("/deleteTeacher")
    public ResultMsg deleteTeacher(@RequestBody Map<String, List<Integer>> map){
        return teacherService.deleteTeacher(map.get("teacherIds"));
    }

}